package com.struts2.student.service;

import java.util.ArrayList;
import java.util.List;

import com.struts2.student.dao.StudentDao;
import com.struts2.student.dao.StudentDaoImpl;
import com.struts2.student.entity.Student;

public class StudentServiceImpl implements StudentService{
	/**
	 * 查询学生信息
	 */
	public List<Student> selectStudent() {
		List<Student> studentList = new ArrayList<Student>();
		StudentDao studentDao = new StudentDaoImpl();
		studentList = studentDao.findStudent();
		return studentList;
	}
	/**
	 * 根据id查询学生信息
	 */
	public Student getStudent(Integer studentId) {
		Student student = null;
		if(studentId!=null){
			StudentDao studentDao = new StudentDaoImpl();
			student = studentDao.get(Student.class, studentId);
		}
		return student;
	}
	/**
	 * 保存学生信息
	 */
	public void save(Student student) {
		StudentDao studentDao = new StudentDaoImpl();
		studentDao.saveOrUpdate(student);
	}
	/**
	 * 根据id删除学生信息
	 */
	public void delete(Integer studentId) {
		Student student = new Student();
		student.setStudentId(studentId);
		StudentDao studentDao = new StudentDaoImpl();
		studentDao.delete(student);
	}

}
